<template>
  <el-container>
    <el-header>
      <el-menu
        :default-active="activeIndex2"
        class="el-menu-demo"
        mode="horizontal"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
        <el-menu-item style="width: 250px" class="left1">
          <img src="../../assets/logo.png">
          <span>共享轮椅后台管理系统</span>
        </el-menu-item>
        <el-submenu index="3" class="right2">
          <template  slot="title" v-if="!showAdminName">我的工作台</template>
          <template  slot="title" v-if="showAdminName">{{adminName}}</template>
          <el-menu-item index="2-3" @click="signOut">退出登录</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-header>
    <el-container>
      <el-aside width="190px" style="overflow: hidden">
        <el-col :span="12">
          <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          style="width: 189px"
          active-text-color="#ffd04b">
          <el-menu-item index="1">
            <i class="el-icon-setting"></i>
            <span slot="title">导航1</span>
          </el-menu-item>
          <el-menu-item index="2">
            <i class="el-icon-menu"></i>
            <router-link to="/backstage/user" replace class="cloo1">租户用户模块</router-link>
          </el-menu-item>
          <el-menu-item index="3" >
            <i class="el-icon-document"></i>
            <router-link to="/backstage/wheelchair" replace class="cloo1">共享轮椅信息模块</router-link>
          </el-menu-item>
          <el-menu-item index="4">
            <i class="el-icon-setting"></i>
            <router-link to="/backstage/rent" replace class="cloo1">租用时长模块</router-link>
          </el-menu-item>
          <el-menu-item index="5">
            <i class="el-icon-s-promotion"></i>
            <router-link to="/backstage/statistics" replace class="cloo1">信息统计模块</router-link>
          </el-menu-item>
          <el-menu-item index="6">
            <i class="el-icon-s-home"></i>
            <router-link to="/backstage/hospital" replace class="cloo1">医院管理模块</router-link>
          </el-menu-item>
        </el-menu>
        </el-col>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {reqAdminIdInfo} from "../../api";

export default {
  name: "backstage",
  data() {
    return {
      showAdminName:false,
      adminName:'',
      activeIndex: '1',
      activeIndex2: '1'
    };
  },
  created() {
    this.getAdminInfo()
  },
  mounted() {

  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //退出登录
    async signOut(){
      await this.$store.dispatch('adminLogout')
      localStorage.removeItem('ADMINTOKEN')
      this.$router.replace('/')
    },
    //通过ID获取用户信息
    async getAdminInfo(){
      let result = await reqAdminIdInfo()
      if (result.code === 1){
        this.showAdminName = true
        this.adminName = result.data.username
      }else {
        this.$message.error(result.msg);
        this.showAdminName = false
        localStorage.removeItem("ADMINTOKEN")
        this.$router.replace('/')
      }
    }
  }

}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
}
.left2{
  position: absolute;
  /*left: 1100px;*/
  right: 150px;
}
.right1{
  position: absolute;
  right: 141px;
}
.right2{
  position: absolute;
  right: 0;
}
.left1{
  position: relative;
  left: 0;
}
.el-header{
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.cloo1{
  text-decoration: none;
  font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  font-size: 15px;
  color: 	#100000 ;
}
.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
.el-aside{
  background: #545c64;
}
.el-container{
  position: absolute;
  width: 100%;
  top: 0 ;
  left: 0 ;
  bottom: 0;
}
.el-header{
  padding: 0;
  z-index: 1000;
}
.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
</style>
